<template>
  <div id="app">
    <router-view :userinfo="userinfo" @userinfoUpdate="updateUserInfo" v-if="maskDisplay=='none'" />
    <div class="mask" :style="{display:maskDisplay}">
      <van-loading color="#1989fa" vertical>系统载入中...</van-loading>
    </div>
  </div>
</template>

<script>
import global_ from './Global';
export default {
  name: 'App',
  data(){
    return {
      maskDisplay:'flex',
      userinfo:null
    }
  },
  created: function () {
    var that = this;
    if(this.$route.name == "/login" || this.$route.name == "/register"){
      that.maskDisplay = 'none';
      return;
    }
    this.$axios.get(global_.serverUrl+"admin/index/userinfo").then(function (response) {
      that.maskDisplay = 'none';
      if(response.code != 1){
        that.$router.replace({path:"/login"});
      }else{
        that.userinfo = window.loginInfo = response.data;
        //that.$router.replace({path:'/'});
      }
    }).catch(function (error) {
      that.maskDisplay = 'none';
      that.$router.replace({path:"/login"});
    });
  },
  methods:{
    updateUserInfo:function (data) {
      this.userinfo = data;
    }
  }
}
</script>

<style>
.mask{
  width: 100%;
  height: 100vh;
  display:flex;
  background: #ffffff;
  position: absolute;
  z-index: 9999999;
  top: 0px;
  left: 0px;
  justify-content:center;
  align-items:center;
}
</style>
